﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HCFramework.API.LINQ;
using System.IO;

namespace HCFramework.Product.Detail.Control
{
    public partial class ListImage : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public void BindImages(HCFramework.API.LINQ.Product product)
        {
            List<ProductImage> listProductImage = product.ProductImages.OrderByDescending(ik=>ik.IsMainImage).ToList();
            if (listProductImage.Count < 2)
            {
                panelListImages.Visible = false;
            }
            else
            {
                litImageItem.Text = "";
                foreach (ProductImage productImage in listProductImage)
                {
                    litImageItem.Text += GetDisplayContent(productImage);
                }
            }
            linkViewMainImage.NavigateUrl = imageMain.ImageUrl = C.ProductImageController.GetMainImageURL(product);
        }

        private string GetDisplayContent(ProductImage productImage)
        {
            string ret = File.ReadAllText(Server.MapPath(@"~\Product\Detail\Template\ImageItem.htm"));
            ret = ret.Replace("{imageUrl}", productImage.URL);
            return ret;
        }
    }
}